cmake_minimum_required (VERSION 3.8)
project(LibDGGSFeature)
set(CMAKE_CXX_STANDARD 17)
if (MSVC)
    add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
endif ()

if (CMAKE_BUILD_TYPE STREQUAL "Debug")
    set(DGGS_OUT_DIR ${CMAKE_OUT_DIR}/out/build/debug)
else ()
    set(DGGS_OUT_DIR ${CMAKE_OUT_DIR}/out/build/release)
endif ()

include_directories("${CMAKE_SOURCE_DIR}/LibDGGSBase")

include_directories("${CMAKE_SOURCE_DIR}/LibDGGSKernel")
link_directories("${DGGS_OUT_DIR}/LibDGGSKernel")

include_directories("${CMAKE_SOURCE_DIR}/3rdlibs/include")
link_directories("${CMAKE_SOURCE_DIR}/3rdlibs/lib")


set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${DGGS_OUT_DIR}/LibDGGSFeature)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${DGGS_OUT_DIR}/LibDGGSFeature)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${DGGS_OUT_DIR}/LibDGGSFeature)

set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

set(CMAKE_DEBUG_POSTFIX D)
set(CMAKE_RELEASE_POSTFIX )

file(GLOB_RECURSE SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
add_library(LibDGGSFeature SHARED ${SOURCE_FILES}
        "DGGSFeature.cpp"
        "DGGSFeatureLayer.cpp"
        "DGGSFeatureClass.cpp"
        "DGGSPoint.cpp"
        "DGGSPolyLine.cpp"
        "DGGSPolygon.cpp"
)

# DLL
target_compile_definitions(LibDGGSFeature PRIVATE BUILDING_DLL)

if(ISEXTRACT)
    file(GLOB_RECURSE MyLIB_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp)
    foreach(header_file ${MyLIB_HEADERS})
        get_filename_component(header_dir ${header_file} DIRECTORY)
        string(REPLACE ${CMAKE_CURRENT_SOURCE_DIR} ${lib_output_directory}/include/LibDGGSFeature output_header_dir ${header_dir})
        file(MAKE_DIRECTORY ${output_header_dir})
        configure_file(${header_file} ${output_header_dir} COPYONLY)
    endforeach()
    if (CMAKE_BUILD_TYPE STREQUAL "Debug")
        add_custom_command(TARGET LibDGGSFeature POST_BUILD
                COMMAND ${CMAKE_COMMAND} -E copy
                ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/LibDGGSFeatureD.lib
                ${lib_output_directory}/lib/debug/LibDGGSFeatureD.lib
                COMMAND ${CMAKE_COMMAND} -E copy
                ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/LibDGGSFeatureD.dll
                ${lib_output_directory}/bin/debug/LibDGGSFeatureD.dll
                COMMENT "Copying LibDGGSFeature debug files..."
        )
    else ()
        add_custom_command(TARGET LibDGGSFeature POST_BUILD
                COMMAND ${CMAKE_COMMAND} -E copy
                ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/LibDGGSFeature.lib
                ${lib_output_directory}/lib/release/LibDGGSFeature.lib
                COMMAND ${CMAKE_COMMAND} -E copy
                ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/LibDGGSFeature.dll
                ${lib_output_directory}/bin/release/LibDGGSFeature.dll
                COMMENT "Copying LibDGGSFeature release files..."
        )
    endif ()
endif()

install(TARGETS LibDGGSFeature
        LIBRARY DESTINATION ${lib_install_directory}/lib
        ARCHIVE DESTINATION ${lib_install_directory}/lib
        RUNTIME DESTINATION ${lib_install_directory}/bin
        PUBLIC_HEADER DESTINATION ${lib_install_directory}/include
)
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/" # source directory
        DESTINATION ${lib_install_directory}/include # target directory
        FILES_MATCHING # install only matched files
        PATTERN "*.hpp" # select header files
)


if (CMAKE_BUILD_TYPE STREQUAL "Debug")
    target_link_libraries(LibDGGSFeature
            LibDGGSKernelD
            jsoncpp
     )
else ()
    target_link_libraries(LibDGGSFeature
            LibDGGSKernel
            jsoncpp
    )
endif ()


 add_dependencies(LibDGGSFeature LibDGGSKernel)